<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">按车间：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="" lay-filter="">
                                            <option value="">车间</option>
                                            <option value="">一车间</option>
                                            <option value="">二车间</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">订单状态：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="" lay-filter="">
                                            <option value="">订单状态</option>
                                            <option value="">待受理</option>
                                            <option value="">已受理</option>
                                            <option value="">配货中</option>
                                            <option value="">配送中</option>
                                            <option value="">已签收</option>
                                            <option value="">完成</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">配货订单编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="" class="layui-input" type="text" placeholder="请输入配货订单编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">创建人：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="" class="layui-input" type="text" placeholder="请输入创建人"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit
                                            type="reset">重置
                                    </button>
                                </div>
                            </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="distributionDemandTable" lay-filter="distributionDemandTable"></table>
        </div>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="distributionDemandTableBar">
    <a class="layui-btn layui-btn layui-btn-xs" lay-event="info">详情</a>
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 表单详情弹窗 -->
<script type="text/html" id="distributionDemandDetail">
    <form lay-filter="distributionDemandDetail" class="layui-form model-form">
        <div class="layui-card-body" style="padding: 0 20px">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="workshopName" lay-filter="">
                        <option value="">车间</option>
                        <option value="">一车间</option>
                        <option value="">二车间</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="" lay-filter="">
                        <option value="">商品品牌</option>
                        <option value="">富兰地</option>
                        <option value="">云端</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="cabCode" lay-filter="">
                        <option value="">所属柜子</option>
                        <option value="">YD1011-2102</option>
                        <option value="">YD1011-2102</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input name="skuCode" class="layui-input" type="text" placeholder="商品编号"/>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input name="" class="layui-input" type="text" placeholder="查看货道编号"/>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <a class="layui-btn icon-btn" lay-filter="formSubSearchLogDetails" lay-submit type="button">搜索</a>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="orderDetailTable" lay-filter="orderDetailTable"></table>
        </div>
    </form>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="distributionDemandForm">
    <form lay-filter="distributionDemandForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">配货订单编号</label>
            <div class="layui-input-block">
                <input name="distCode" placeholder="请输入配货订单编号" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input name="customerName" placeholder="请输入客户名称" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户联系人</label>
            <div class="layui-input-block">
                <input name="customerConcat" placeholder="请输入客户联系人" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人电话</label>
            <div class="layui-input-block">
                <input name="customerMoble" placeholder="请输入联系人电话" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">刀具补货数量</label>
            <div class="layui-input-block">
                <input name="addNum" placeholder="请输入刀具补货数量" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">柜子库存数量</label>
            <div class="layui-input-block">
                <input name="stockNum" placeholder="请输入柜子库存数量" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货值</label>
            <div class="layui-input-block">
                <input name="total" placeholder="请输入货值" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业id</label>
            <div class="layui-input-block">
                <input name="enterpriseId" placeholder="请输入企业id" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">省</label>
            <div class="layui-input-block">
                <input placeholder="请输入省" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">市</label>
            <div class="layui-input-block">
                <input name="city" placeholder="请输入市" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">区</label>
            <div class="layui-input-block">
                <input name="area" placeholder="请输入区" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详情地址</label>
            <div class="layui-input-block">
                <input name="address" placeholder="请输入详情地址" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态：replay_comfire(1,待确认);replay_dev(2,待配送);replay_
                sign(3,待签收);complete(4,已签收);：</label>
            <div class="layui-input-block">
                <input name="status"
                       placeholder="请输入状态：replay_comfire(1,待确认);replay_dev(2,待配送);replay_ sign(3,待签收);complete(4,已签收);："
                       type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">unitId</label>
            <div class="layui-input-block">
                <input name="unitId" placeholder="请输入unitId" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">unitName</label>
            <div class="layui-input-block">
                <input name="unitName" placeholder="请输入unitName" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">workshopId</label>
            <div class="layui-input-block">
                <input name="workshopId" placeholder="请输入workshopId" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">workshopName</label>
            <div class="layui-input-block">
                <input name="workshopName" placeholder="请输入workshopName" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建者</label>
            <div class="layui-input-block">
                <input name="creator" placeholder="请输入创建者" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改者</label>
            <div class="layui-input-block">
                <input name="modifier" placeholder="请输入修改者" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人</label>
            <div class="layui-input-block">
                <input name="creatorName" placeholder="请输入创建人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改人</label>
            <div class="layui-input-block">
                <input name="modifierName" placeholder="请输入修改人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        // 渲染表格
        var insTb = table.render({
            elem: '#distributionDemandTable',
            url: config.base + 'enterprisecab/order/admin/distributionDemand/list',
            page: true,
            cellMinWidth: 120,
            cols: [[
                // {field: 'id', sort: true, title: 'ID'}
                {type: 'numbers', title: '序号'}
                , {field: 'distCode', sort: true, title: '配货订单编号'}
                , {field: 'customerName', sort: true, title: '所属公司'}
                , {field: 'stockNum', sort: true, title: '物料数量'}
                , {field: 'addNum', sort: true, title: '补货柜子数'}
                , {field: 'total', sort: true, title: '订单货值'}
                , {field: 'creator', sort: true, title: '创建人'}
                , {field: 'statusDesc', sort: true, title: '状态'}
                , {field: 'createTime', sort: true, title: '创建时间'}
                , {align: 'center', toolbar: '#distributionDemandTableBar', title: '操作'}
            ]],

        });

        // 工具条点击事件
        table.on('tool(distributionDemandTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'info') { //修改
                showDetailModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }
        });

        //监听排序
        table.on('sort(distributionDemandTable)', function (obj) {
            table.reload('distributionDemandTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#distributionDemandBtnAdd').click(function () {
            showEditModel();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '940px',
                offset: '65px',
                title: data ? '配货订单详情' : '添加配货需求订单表',
                content: $('#distributionDemandForm').html(),
                success: function () {
                    form.val('distributionDemandForm', data);
                    // 表单提交事件
                    form.on('submit(distributionDemandFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/order/admin/distributionDemand/update' : 'enterprisecab/order/admin/distributionDemand/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('distributionDemandTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 显示详情弹窗
        function showDetailModel(data) {
            admin.open({
                type: 1,
                area: ['1500px', '700px'],
                offset: '65px',
                title: '配货需求详情',
                content: $('#distributionDemandDetail').html(),
                success: function () {
                    form.render('select');
                    var insTb3 = table.render({
                        elem: '#orderDetailTable',
                        url: config.base + "enterprisecab/order/admin/distributionDemandDetail/list?id=" + data.id,
                        page: true,
                        cellMinWidth: 115,
                        cols: [[
                            // {field: 'id', title: 'ID', width: 60}
                            {type: 'numbers', title: '序号'}
                            , {field: '', title: '需求编号'}
                            , {field: 'workshopName', title: '所属车间'}
                            , {field: 'cabCode', title: '刀归编号'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'productName', title: '物料系列名称'}
                            , {field: '', title: '规格'}
                            , {field: 'unitId', title: '单位'}
                            , {field: 'curentStock', title: '当前库存'}
                            , {field: 'alarmStock', title: '告警数'}
                            , {field: 'planReplenishment', title: '计划补货'}
                            , {field: 'quantityConfirm', title: '确定补货'}
                            , {field: 'createTime', title: '确定时间'}


                            // , {field: 'alarmCode', title: '告警编号'}
                            // , {field: 'cabCode', title: '柜子编号'}
                            // , {field: 'workshopName', title: '车间'}
                            // , {field: 'productName', title: '物料系列名称'}
                            // ,  {field: 'skuCode', title: '物料编号'}
                            // , {field: 'unitId', title: '单位'}
                            // , {field: 'curentStock', title: '当前库存'}
                            // , {field: 'alarmStock', title: '告警库存'}
                            // , {field: 'proposalStock', title: '建议补货'}
                            // , {field: 'planReplenishment', title: '计划补货'}
                            // , {field: 'quantityConfirm', title: '确认补货'}
                            // , {field: 'statusDesc', title: '状态'}
                            // , {field: 'createTime', title: '记录时间'}
                        ]]
                    });

                    // 搜索
                    form.on('submit(formSubSearchLogDetails)', function (data) {
                        insTb3.reload({where: data.field, page: {curr: 1}}, 'data');
                    });
                }
            });
        }


        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/order/admin/distributionDemand/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        form.render('select');
        // 导出excel
        $('#distributionDemandBtnExport').click(function () {
            var checkRows = table.checkStatus('distributionDemandTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>